<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../css/auislide.css" />
    <link rel="stylesheet" type="text/css" href="../css/play.css" />
    <style type="text/css">
        html,
        body {
            background-color: #efefef;
            overflow: visible !important;
        }

        .aui-tabBar-fixed {
            position: fixed;
            bottom: 0;
            left: 0;
            z-index: 49;
        }

        .aui-class-list-title {
            padding: 5px 15px;
            background: #f2efee;
            width: 100%;
            position: relative;
            font-size: 0.7rem;
        }

        .aui-class-list-item {
            display: flex;
            -webkit-box-align: center;
            align-items: center;
            width: 30%;
            float: left;
            position: relative;
            z-index: 0;
            height: 60px;
            margin-left: 3%;
        }

        .aui-class-list-box {
            background: #fff;
            overflow: hidden;
        }

        .aui-cell-fl img {
            width: 25px;
            margin-right: 15px;
            display: block;
            border: none;
            border-radius: 3rem;
        }

        .aui-cell-fr {
            -webkit-box-flex: 1;
            -webkit-flex: 1;
            flex: 1;
            color: #fff;
            font-size: 0.6rem;
        }

        .wz {
            margin: 0 auto;
            width: 96%;
            font-size: 10px;
            background-color: #ffeb3c;
            border-radius: 0.1rem;
            height: 20px;
            margin-top: 10px;
            text-align: center;
            color: #4e4e4c;
        }

        .play {
            margin-top: 90%;
            background: linear-gradient(to right, #03bbf4 0, #d800ff 250%);
        }
    </style>
</head>

<body style="background-image:  url(../image/sy.png);background-repeat: no-repeat;background-size: 120px 40px;background-position: 50% 100%;">
<header class="aui-navBar aui-navBar-fixed" style="background: linear-gradient(to right,#03bbf4 0,#d800ff 250%);position: relative;padding-top:25px;" id="header">
    <a tapmode onclick="closeWin()" class="aui-navBar-item" tyle="color: #c4c4c4;">
        <i style="position: absolute;width: 12px;height: 12px;border: solid #fff;border-width: 1px 0 0 1px;transform: rotate(-45deg)!important;"></i>
    </a>
    <div class="aui-center">
        <span class="aui-center-title" id="title" style="color: #fff;"> 正在播放 </span>
        <!--<img src="../image/d_02.png" style="width:25px;float:right;" onclick="browse()">-->
    </div>
</header>
<div class="play">
    <!--<img src="../image/d_04.png" style="width: 50px;height: 20px;position: absolute;float:  right;right: 10%;margin-top: -10px;">-->
    <a onclick="Fx()" class="aui-class-list-item">
        <div class="aui-cell-fl">
            <img src="../image/d_01.png" alt="">
        </div>
        <div class="aui-cell-fr">分享推荐</div>
    </a>
    <a onclick="browse()" class="aui-class-list-item">
        <div class="aui-cell-fl">
            <img src="../image/d_02.png" alt="">
        </div>
        <div class="aui-cell-fr">投屏</div>
    </a>
    <a id="play" onclick="jieXi()" class="aui-class-list-item">
        <div class="aui-cell-fl">
            <img src="../image/d_03.png" alt="">
        </div>
        <div class="aui-cell-fr">更换线路</div>
    </a>
</div>
<div class="gonggao" style=" border-radius: 0px 0px 30px 30px; box-shadow: 0.01rem 0.15rem 0.1rem rgba(0, 0, 0, 0.05);height: 1.3rem">
    <div class="list-title-l">
        <i class="" id="gonggao-l" style="background: linear-gradient(to right,#1613d6, #181be6); -webkit-background-clip: text; color: transparent;font-size: 0.7rem">
            <b>全屏方法:</b>
        </i>
    </div>

    <div class="gonggao-r" id="gonggao-r" style="float:right;width: 89%;position: absolute;text-align: center;right: 1rem;left: 3.8rem;width: auto;">
        <marquee scrollamount="5">
            <span id="gonggao" style="background: linear-gradient(to right, #00e7ff, #d800ff); -webkit-background-clip: text; color: red;font-size: 0.7rem;padding-top:0.3rem;">①:手机打开旋转功能，②:点击全屏按钮，③:手机横着就即可全屏，④:如果卡顿更换线路即可</span>
        </marquee>
    </div>
</div>
<!--<div class="wz">切换线路时</div>-->
<!--<div class="wz">影片中出现的文字广告请勿相信，谨防上当受骗！</div>-->
<div style="padding: 20px">
    <img id="bpic" style="border-radius: 25px;" src="../image/default_picture/mike.png" onClick="ompleted()">
</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/mike_no.js"></script>
<script type="text/javascript" src="../script/date.min.js"></script>
<script type="text/javascript">
    var dkplayer;
    var dkplayerUrl;
    var isbrowse = 1;
    var uz;
    apiready = function () {
        api.parseTapmode();
        leCastDemo = api.require('leCast');
        leCastDemo.initLeCast(); //模块初始化方法，必须在所有方法调用前调用
        uzmoduledemo = api.require('androidBrowser');
        uz = api.require('zhikeia');
        var header = $api.byId('aui-header');
        $api.fixStatusBar(header);
        var headerPos = $api.offset(header);
        var body_h = $api.offset($api.dom('body')).h;
        api.addEventListener({
            name: 'keyback'
        }, function (ret, err) {
            goback();
        });

        api.setScreenOrientation({
            orientation: 'auto' //屏幕根据重力感应在横竖屏间自动切换 auto_portrait
        });

        var param = {
            /*
            x:浏览器窗口X位置，默认0
            y:浏览器窗口y位置，默认0
            w:浏览器宽度，默认满屏
            h:浏览器高度，默认满屏
            */
            rect: {
                x: 0,
                y: $api.dom('header').offsetHeight,
                w: 'auto',
                h: '300',
            }, //w,h等于0代表横向满屏和纵向满屏
            fixedOn: "", //浏览器依附在哪个window,不传或传空 为 当前Window，默认当前当前Window
            fixed: true, //浏览器是否随frame或Window滑动，默认当前当前true
            url: api.pageParam.url, //要加载的url,可选项
            browserBg: "#F0F0F0", //可选
            timeout: 7, //超时时间,指加载页面完毕后等待多少秒，超过这个时间还没收到视频地址，则认为解析视频地址失败。默认7秒

        };
        uzmoduledemo.openView(param, function (ret, err) {
            //alert(JSON.stringify(ret));
            if (ret.result == '1') {
                TVURL = ret.VideoUrl;
                dkplayerUrl = TVURL;
                convertTips(true);
                uzmoduledemo.closeView(function (ret, err) {
                    //alert(JSON.stringify(ret));
                });
            }
            /*
            返回值：
            result：1找到视频，2加载完毕
            MainUrl：参数传入的url字段
            VideoUrl：解析到的视频地址

            */
        });
        xx(api.pageParam.url);
        var browser = api.require('webBrowser');
        browser.openView({
            url: api.pageParam.url,
            rect: {
                x: 0,
                y: $api.dom('header').offsetHeight,
                w: 'auto',
                h: 300,
            }
        }, function (ret, err) {
            switch (ret.state) {
                case 0:
                    break;
                case 1:
                    break;
                case 2:
                    break;
                case 3:
                    break;
                case 4:
                    break;
                default:
                    break;
            }
            ;
        });
        if (api.pageParam.needRecordHistory) {
            record_play_history();
        }
        //渲染广告
        getbpic()
    }
    function getbpic() {
        var api_url=localStorage.getItem('api_url');
        api.ajax({
            url: api_url + '/login/login/getbpic.html',
            method: 'get',
            data: {
                values: {
                    uid: localStorage.getItem('user_id'),
                    mike_key: localStorage.getItem('mike_key')
                }
            }
        }, function (ret, err) {
            if (ret) {
                //渲染图片广告
                var bpic = $api.byId('bpic');
                bpic.src = api_url+"/" + ret.msg.m112
                localStorage.setItem('m113',ret.msg.m113)
            }
        });
    }
    /**
     *
     * 切换提示
     */
    function convertTips(isDkPlayer) {
        var tips1 = "全屏方法:";
        var tips1Content = '<marquee scrollamount="5"><span id="gonggao" style="background: linear-gradient(to right, #00e7ff, #d800ff); -webkit-background-clip: text; color: red;font-size: 0.7rem;padding-top:0.3rem;">①:手机打开旋转功能，②:点击全屏按钮，③:手机横着就即可全屏，④:如果卡顿更换线路即可</span></marquee>';
        var tips2 = "温馨提示:";
        var tips2Content = '<span id="gonggao" onclick = "qiehuan()" style="background: linear-gradient(to right, #00e7ff, #d800ff); -webkit-background-clip: text; color: red;font-size: 0.7rem;padding-top:0.3rem;">点此可切换全屏倍速播放器和屏蔽广告</span>';
        var tip = isDkPlayer ? tips2 : tips1;
        var content = isDkPlayer ? tips2Content : tips1Content;
        document.getElementById("gonggao-r").innerHTML = content;
        document.getElementById("gonggao-l").innerHTML = tip;
    }
    function goback() {
        if (isbrowse == 1) {
            api.closeWin();
            return;
        }
        dkplayer.isLock(function (ret) {
            if (ret.code == 0) {
                if (ret.isLock) {
                    api.toast({
                        msg: '请先解锁屏幕！',
                        global: true
                    });
                } else {
                    isFullscreen();
                }
            }
        });
    }
    function isFullscreen() {
        dkplayer.isFull(function (ret) {
            if (ret.code == 0) {
                if (ret.isFull) {
                    api.setScreenOrientation({
                        orientation: 'portrait_up'
                    });
                    var tinyPlayers = api.require('tinyPlayer');
                    tinyPlayers.exitFullScreen();
                } else {
                    api.closeWin();
                }
            }
        });
    }
    /**
     * 切换播放器
     *
     */
    function qiehuan() {
        api.hideProgress();
        if (isbrowse == 0) {
            dkplayer.remove();
        } else {
            var browsers = api.require('webBrowser');
            browsers.closeView();
        }
        goplay_dkplayer(dkplayerUrl);
    }
    function goplay_dkplayer(TVURL) {
        //toast('正在努力为您获取资源 请稍等···', 3000);
        isbrowse = 0;
        dkplayer.addEventListener(function (ret) {
            var code = ret.code;
            if (code == 0) {
                api.closeWin();
            } else if (code == 9) {
                //zdhx();
            } else if (code == 2) {
                alert(JSON.stringify(ret))
            } else if (code == 26) {
                alert(JSON.stringify(ret))
            }
        });
        dkplayer.showInView({
            rect: { x: 0, y: $api.dom('header').offsetHeight, w: 'auto', h: 300 },
            fixedOn: api.frameName,
            fixed: false,
            isLive: false,//是否直播
            forceDeviceOrientation: true,//旋转方向 true 全屏视频不旋转
            radius: 5,//圆角大小 默认 0 没有圆角
            showBack: false,//返回按钮是否显示小屏幕
            showSelect: false,//选集按钮是否显示
            showSpeed: true,//倍速按钮是否显示
            showShot: true,//截图按钮是否显示
            showBottomProcess: true,
            autoPlay: true,//默认false
            openCache: false,//是否开启缓存
            //styles:styles,//只定义控件
            hideControl: false,//是否隐藏所有控件
            backgroundHolder: 'widget://image/loading_wap.gif',//视频背景图片 空显示视频封面
            backgroundAlpha: 0.3,//0 背景透明度
            loop: false,//是否单急循环
            index: 0,
            data: [
                {
                    uid: '',//扩展字段 用户id(可选，会随事件返回)
                    vid: '',//扩展字段 视频id(可选，会随事件返回)
                    title: "",
                    index: '01',
                    //thumb:'https://cms-bucket.nosdn.127.net/eb411c2810f04ffa8aaafc42052b233820180418095416.jpeg',
                    url: TVURL
                }
            ]
        });
    }
    function ompleted() {
        api.openWin({
            name: 'h5',
            url: './h5.html',
            pageParam: {
                url: localStorage.getItem('m113')
            }
        });
    }

    //获取字幕
    // function getCaption(obj){
    //   var index=obj.lastIndexOf("\=");
    //   obj=obj.substring(index+1,obj.length);
    //   return obj;
    // }

    //关闭播放窗口
    function closeWin() {
        api.setScreenOrientation({
            orientation: 'portrait_up'
        });
        dkplayer.remove();
        api.closeWin();
    }

    function jieXi() {
        api.actionSheet({
            title: '影视VIP线路',
            cancelTitle: '取消',
            buttons: ['VIP线路1', 'VIP线路2', 'VIP线路3', 'VIP线路4', 'VIP线路5', 'VIP线路6', 'VIP线路7', 'VIP线路8', 'VIP线路9']
        }, function (ret, err) {
            var index = ret.buttonIndex;
            if (ret.buttonIndex == 1) {
                vipHuanxian(localStorage.getItem('jx_url2'));
            }
            if (ret.buttonIndex == 2) {
                vipHuanxian(localStorage.getItem('jx_url3'));
            }
            if (ret.buttonIndex == 3) {
                vipHuanxian(localStorage.getItem('jx_url4'));
            }
            if (ret.buttonIndex == 4) {
                vipHuanxian(localStorage.getItem('jx_url5'));
            }
            if (ret.buttonIndex == 5) {
                vipHuanxian(localStorage.getItem('jx_url6'));
            }
            if (ret.buttonIndex == 6) {
                vipHuanxian(localStorage.getItem('jx_url7'));
            }
            if (ret.buttonIndex == 7) {
                vipHuanxian(localStorage.getItem('jx_url8'));
            }
            if (ret.buttonIndex == 8) {
                vipHuanxian(localStorage.getItem('jx_url9'));
            }
            if (ret.buttonIndex == 9) {
                vipHuanxian(localStorage.getItem('jx_url10'));
            }
        });
    }
    function xx(url) {
        var tid = 0;
        uz.ia({
            url: url
        }, function (ret, err) {
            reurl = unescape(ret.url);
            if (reurl.indexOf("=http://") != -1) { } else if (reurl.indexOf("=https://") != -1) { } else {
                if (tid == 0) {
                    tid = 1;
                    TVURL = reurl;
                    dkplayerUrl = reurl;
                    convertTips(true);
                }
            }
        });
    }
    function vipHuanxian(jiekou) {
        api.hideProgress();
        convertTips(false);
        xx(jiekou + api.pageParam.srcUrl);
        var browser = api.require('webBrowser');
        if (isbrowse == 0) {
            dkplayer.remove();
            browser.openView({
                url: jiekou + api.pageParam.srcUrl,
                rect: {
                    x: 0,
                    y: $api.dom('header').offsetHeight,
                    w: 'auto',
                    h: 300,
                }
            }, function (ret, err) {
                switch (ret.state) {
                    case 0:
                        break;
                    case 1:
                        break;
                    case 2:
                        break;
                    case 3:
                        break;
                    case 4:
                        break;
                    default:
                        break;
                }
                ;
            });
            isbrowse = 1;
        } else {
            browser.loadUrl({
                url: jiekou + api.pageParam.srcUrl
            });
        }

    }

    function record_play_history() {
        //alert(api.pageParam.title);
        api.ajax({
            url: localStorage.getItem('api_url') + '/login/login/jilu?uid=3',
            data: {
                values: {
                    uid: localStorage.getItem('user_id'),
                    title: api.pageParam.title,
                    url: api.pageParam.srcUrl,
                    time: new Date().format('yyyy-MM-dd hh:mm:ss'),
                    ping: getPing(api.pageParam.srcUrl)
                }
            }
        }, function (ret, err) {
        });
    }

    function getPing(url) {
        if (url.indexOf("youku.com") > 0) {
            return '优酷';
        } else if (url.indexOf("iqiyi.com") > 0) {
            return '爱奇艺';
        } else if (url.indexOf("v.qq.com") > 0) {
            return "腾讯"
        } else if (url.indexOf("tv.sohu.com") > 0) {
            return "搜狐"
        } else if (url.indexOf("pptv.com") > 0) {
            return "PPTV"
        } else if (url.indexOf("mgtv.com") > 0) {
            return "芒果"
        } else if (url.indexOf("1905.com") > 0) {
            return "M1905"
        } else if (url.indexOf("baofeng.com") > 0) {
            return "暴风"
        } else if (url.indexOf("le.com") > 0) {
            return "乐视"
        } else if (url.indexOf("xxooweizhiurl.com") > 0) {
            return "未知"
        }

    }

    //分享推荐
    function Fx() {
        api.openWin({
            name: 'share_win',
            url: 'share_win.html',
        });
    }

    //投屏帮助 /////
    function Tp() {
        api.openWin({
            name: 'daili_guanli_win',
            url: './tp_win.html',
            delay: 100,
            pageParam: {
                url: localStorage.getItem('api_url') + '/tp/tp.png'
            },
            bgColor: 'rgba(0,0,0,0)'
        });
    }

    function TpPlay() {
        var LBAirDrop = api.require('LBAirDrop');
        LBAirDrop.searchList(function (ret) {
            alert(JSON.stringify(ret));
        });
    }

    //搜索设备
    function browse() {
        api.showProgress({
            title: '搜索设备中……',
            text: '请稍等...',
            modal: true
        });
        //var param = {browseType:1};
        var param = {
            browseType: 0
        };
        leCastDemo.browse(param, function (ret, err) {
            if (ret.result == '1') {
                //alert(JSON.stringify(ret));
                console.log(JSON.stringify(ret));
                var arr = [];
                var deviceList = ret.deviceList;
                for (var i = 0; i < ret.deviceList.length; i++) {
                    arr.push(ret.deviceList[i]["name"]);
                }
                console.log('Arr=' + arr);
                if (arr.length > 0) {
                    api.actionSheet({
                        title: '请选择接收设备',
                        cancelTitle: '取消',
                        buttons: arr
                    }, function (ret, err) {
                        var index = ret.buttonIndex;
                        uid1 = deviceList[index - 1]['ip'];
                        stopBrowse();//停止搜索方法
                        connect();//链接设备
                    });
                } else {

                    api.hideProgress();
                    api.toast({
                        msg: '未搜索到其他设备',
                        duration: 1000
                    });
                }
                api.hideProgress();
            }


        });
    }
    //停止搜索附近的接收端设备
    /*
      因为browse方法会不停的搜索，所以要在适当的时候调用stopBrowse方法
      返回字段说明：
          {result:1
          }
      */
    function stopBrowse() {
        leCastDemo.stopBrowse(function (ret, err) {
            //alert(JSON.stringify(ret));
        });
    }
    //通过uid连接,在browse回调中获取搜索到的uid
    function connect() {
        //var param = {serviceInfoUid: uid1}; //传入uid  1474652758755455217
        var param = { serviceInfoIp: uid1 };//传入Ip
        leCastDemo.connect(param, function (ret, err) {
            //alert(JSON.stringify(ret));
            if (ret) {
                stopBrowse();
                //startMirror();
                play();
            }
        });
    }
    //播放媒体
    function play() {
        //var wd = $api.val($api.byId('url1'));
        //console.log(wd);
        var param = {
            directPlay: 0, //是否直接播放，1无需连接设备直接播放(但需要先搜索)，0需连接设备(默认)
            connectedUid: uid1, //直接播放的设备的uid(需要先搜索获取)，directPlay为1时该字段必须要传
            screenCode: "", //有些屏幕需要投屏码的就要传，可选项
            mediaType: 2, //媒体类型：数字型，1音乐,2视频，3图片
            localUrl: "", //本地媒体路径，支持widget://,fs://,安卓系统标准文件路径
            netUrl: TVURL, //网络文件路径,http://...
            //这两个url必须要传一个，两个都传时只认localUrl
        };
        leCastDemo.play(param, function (ret, err) {
            if (ret.status != 25) { //播放进度已更新不弹窗，避免弹窗过多
                //alert(JSON.stringify(ret));
                //var msg = JSON.stringify(ret.msg);
                api.toast({
                    msg: '开始播放',
                    duration: 1000
                });
                var dlna = $api.byId('dlna');
                dlna.style = "display:none";
            }
        });
    }
</script>

</html>